/*OWmq6Ugo6jPE4W7xoi1UXlXa6Uo/GAeDS7JN8mWOERFI1YSIxjzhvlCZGmRoUoRn*/
import { ajax, toast, getBusinessInfo } from 'nc-lightapp-front';
import { pagecode, funCode, cytjCode_auto, bfCode_auto, dfCode_auto, publicCode_auto, hxgzCode_auto, hxfsCode } from '../constants';
import { setAllFieldEditable, setFieldDisabledAR, loadVerifyFa, writeBack } from '../../../public/publicMethods/pubUtils.js';
import { jf_hxdxCBox_AfterEvent, jfBillTypeBox_AfterEvent, df_hxdxCBox_AfterEvent } from '../../../public/publicMethods/pubAfterEventAR.js';
import {
	hldcChkBox_AfterEvent,
	tbzhxChkBox_AfterEvent,
	ybzhxChkBox_AfterEvent,
	zjbzRef_AfterEvent,
	jfbzRef_AfterEvent,
	jfbz_dzjbzhlTxtF_AfterEvent,
	jfbz_dbbhlTxtF_AfterEvent,
	dfbzRef_AfterEvent,
	dfbz_dzjbzhlTxtF_AfterEvent,
	dfbz_dbbhlTxtF_AfterEvent
} from '../../../public/publicMethods/pubAfterEvent.js';
import { setDefaultValue } from './buttonClick';


export default function afterEvent(props, moduleId, key, value, oldValue) {
	// props, moduleId(区域id), key(操作的键), value（当前值），oldValue(旧值)
	let that = this
	let cytjCode = this.cytjCode;
	let bfCode = this.bfCode;
	let dfCode = this.dfCode;
	let publicCode = this.publicCode;
	let hxgzCode = this.hxgzCode;

	//常用条件编辑后事件
	if (moduleId == cytjCode || moduleId == cytjCode_auto) {
		if (moduleId == cytjCode_auto) {
			cytjCode = cytjCode_auto
			bfCode = bfCode_auto
			dfCode = dfCode_auto
			publicCode = publicCode_auto
			hxgzCode = hxgzCode_auto
		}

		if (key == 'pk_org' && value.value != null && value.value != "") {
			//设置常用条件所有字段可编辑
			let arr = [cytjCode, bfCode, dfCode, publicCode]
			setAllFieldEditable(props, cytjCode, arr, true);
			props.form.setFormItemsDisabled(cytjCode, { jfBillTypeBox: true });
			props.form.setFormItemsDisabled(cytjCode, { dfBillTypeBox: true });
			props.form.setFormItemsRequired(hxgzCode, { 'jefxCmbBox': false })

			if (!oldValue || value.value != oldValue.value) {
				//加载核销方案和默认币种
				loadVerifyFa(props, cytjCode, hxgzCode, value, funCode);
			}
		}

		//方案加载
		if (key == 'verifyFa') {
			if (value.value && value.value != "null" && value.value != null) {
				ajax({
					url: '/nccloud/arap/verifyfa/edit.do',
					async: false,
					data: {
						pk_bill: value.value,
						pageId: pagecode,
						cytjCode: cytjCode,
						hxgzCode: hxgzCode,
						hxfsCode: hxfsCode
					},
					success: function (res) {
						if (res.success) {
							if (res.data) {
								writeBack(that, res, props, moduleId, cytjCode, cytjCode_auto, bfCode, dfCode, publicCode, hxgzCode, hxfsCode);
								props.form.setFormItemsValue(cytjCode, { 'verifyFa': value });
							}
						}
					}
				})
			} else {
				let pk_org = props.form.getFormItemsValue(cytjCode, 'pk_org')
				let verifyFa = props.form.getFormItemsValue(cytjCode, 'verifyFa')
				//设置默认值
				setDefaultValue(this, props, cytjCode, bfCode, dfCode, publicCode, hxgzCode)
				props.form.setFormItemsValue(cytjCode, { 'pk_org': pk_org })
				props.form.setFormItemsValue(cytjCode, { 'verifyFa': verifyFa })
				afterEvent.call(this, props, cytjCode, 'pk_org', pk_org, pk_org)
			}
		}

		// 本方核销对象
		if (key == 'jf_hxdxCBox') {
			jf_hxdxCBox_AfterEvent(this, props, value, cytjCode, bfCode, dfCode);
		}

		//本方单据类型
		if (key == 'jfBillTypeBox') {
			jfBillTypeBox_AfterEvent(this, props, value, cytjCode, bfCode, dfCode);
		}

		// 对方核销对象
		if (key == 'df_hxdxCBox') {
			df_hxdxCBox_AfterEvent(this, props, value, cytjCode, bfCode, dfCode);
		}

		//根据数据控制字段可编辑性
		setFieldDisabledAR(props, cytjCode)

	}

	//核销规则编辑后事件
	if (moduleId == hxgzCode || moduleId == hxgzCode_auto) {
		if (moduleId == hxgzCode_auto) {
			cytjCode = cytjCode_auto
			bfCode = bfCode_auto
			dfCode = dfCode_auto
			publicCode = publicCode_auto
			hxgzCode = hxgzCode_auto
		}

		//红蓝对冲
		if (key == 'hldcChkBox') {
			hldcChkBox_AfterEvent(this, props, value, cytjCode, bfCode, dfCode, publicCode, hxgzCode);
		}

		//同币种核销，控制异币种核销信息字段不可编辑
		if (key == 'tbzhxChkBox') {
			tbzhxChkBox_AfterEvent(this, props, value, cytjCode, bfCode, dfCode, publicCode, hxgzCode);
		}

		//异币种核销
		if (key == 'ybzhxChkBox') {
			ybzhxChkBox_AfterEvent(this, props, value, cytjCode, bfCode, dfCode, publicCode, hxgzCode);
		}

		//中间币种
		if (key == 'zjbzRef' && value.value) {
			zjbzRef_AfterEvent(this, props, value, cytjCode, bfCode, dfCode, publicCode, hxgzCode, 'ar');
		}

		//借方币种
		if (key == 'jfbzRef' && value.value) {
			jfbzRef_AfterEvent(this, props, value, cytjCode, bfCode, dfCode, publicCode, hxgzCode, 'ar');
		}

		//借方币种-对中间币种汇率 
		if (key == 'jfbz_dzjbzhlTxtF') {
			jfbz_dzjbzhlTxtF_AfterEvent(this, props, value, cytjCode, bfCode, dfCode, publicCode, hxgzCode);
		}

		//借方币种-对本币汇率 
		if (key == 'jfbz_dbbhlTxtF') {
			jfbz_dbbhlTxtF_AfterEvent(this, props, value, cytjCode, bfCode, dfCode, publicCode, hxgzCode);
		}

		//贷方币种
		if (key == 'dfbzRef' && value.value) {
			dfbzRef_AfterEvent(this, props, value, cytjCode, bfCode, dfCode, publicCode, hxgzCode, 'ar');
		}

		//贷方币种-对中间币种汇率 
		if (key == 'dfbz_dzjbzhlTxtF') {
			dfbz_dzjbzhlTxtF_AfterEvent(this, props, value, cytjCode, bfCode, dfCode, publicCode, hxgzCode);
		}

		//贷方币种-对本币汇率 
		if (key == 'dfbz_dbbhlTxtF') {
			dfbz_dbbhlTxtF_AfterEvent(this, props, value, cytjCode, bfCode, dfCode, publicCode, hxgzCode);
		}
	}

}


/*OWmq6Ugo6jPE4W7xoi1UXlXa6Uo/GAeDS7JN8mWOERFI1YSIxjzhvlCZGmRoUoRn*/